/*
 * Copyright (c) 2022.版权所有高金磊
 */

package 领扣算法.A简单题.学生分数的最小差值;

import java.util.Arrays;

public class Main {
    public static void main(String arg[]){//main--来自高金磊

        new Main().minimumDifference(new int[]{9,4,1,7},2);
    }

    public int minimumDifference(int[] nums, int k) {
        if (k<2){
            return 0;
        }

        Arrays.sort(nums);
       int min= Integer.MAX_VALUE;
        for (int i = 0; i < nums.length-k+1; i++) {
            min=Math.min(min, nums[i+k-1]-nums[i]);
        }
        return min;
    }
}
